<template>
    <div id="app" ref="app">
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    name: 'app',
    methods: {
        getdakaGPS() {
            this.$cjc.apiDeviceGetGPS({
                success(data) {
                    this.$store.commit('SET_AddLA', data.result.latitude)
                    this.$store.commit('SET_AddLO', data.result.longitude)
                },
                fail(data) {
                    this.$Message.error(data.msg)
                    console.log(data.msg)
                }
            })
        },
        // 获取是否在校内打卡
        async setGetInSchool() {
            let getInSchool = await this.$store.dispatch('getCheckInSchool', {
                userId: this.$store.state.userInfo.USER_ID,
                plan_id: this.$store.state.NextPlan.PLAN_ID,
                latitude: this.$store.state.getLatitude,
                longitude: this.$store.state.getLonitude,
            })
            if (getInSchool.data.status === 0) {
                this.$store.commit('SET_checkInSchool', getInSchool.data.msg)
            } else if (getInSchool.status === 1) {
                this.$store.commit('SET_checkInSchool', getInSchool.data.msg)
            }
            this.isSchool = getInSchool.data.msg
        }
    },
    created() {
        this.$Message.config({
            top: 300,
            duration: 3
        })
        const Vm = this
        const State = Vm.$store.state
        /**
         * 确认用户信息,并保存用户信息
         */
        async function setUserInfo() {
            if (!State.production) {
                // 调用JS-API登录
                await Vm.$cjc.apiLogin({
                    appKey: '0000',
                    success: (data) => { // 执行成功回调
                        Vm.$cjc.cjcLog('getlogin success' + data)
                    },
                    fail: (data) => { // 执行失败回调 只要是失败 不论是执行失败还是返回值是失败都会进fail
                        Vm.$cjc.cjcLog('getlogin fail' + data)
                    }
                })
                Vm.$cjc.hiddenNavigation()
                let userInfo = await Vm.$cjc.apiGetUserInfor()
                Vm.$store.commit('SET_userInfo', userInfo.result)
                let saveUserInfo = await Vm.$store.dispatch('saveUserInfo', userInfo.result)
                if (saveUserInfo.data.power === 1) {
                    Vm.$router.replace({
                        name: 'examineCondition'
                    })
                }
            } else {
                // 测试账号登录
                let userLogin = await Vm.$store.dispatch('userlogin', {
                    'username': 'zhangyao1',
                    'password': 'a123456',
                    'type': 2
                })
                Vm.$store.commit('SET_userInfo', userLogin.data.result)
                let saveUserInfo = await Vm.$store.dispatch('saveUserInfo', userLogin.data.result)
                if (saveUserInfo.data.power === 1) {
                    Vm.$router.replace({
                        name: 'examineCondition'
                    })
                }
                // Vm.getdakaGPS()
            }
        }
        // 执行步骤
        async function setp() {
            await setUserInfo()
        }
        setp()
    }
}
</script>
<style lang=less>
@size-color:#495060;
body {
    background-color: #f8f8f8;
}
#app {
    height: 100%;
    background-color: #f8f8f8;
    padding-top: 50px;
}
</style>

